<template>
  <el-form :model="form" :rules="rules" ref="form" label-width="55px" class="demo-ruleForm login-container" style="margin:0 auto;position:relative;top:16%">
    <h2 class="title">配资登录</h2>
    <el-form-item prop="username">
      <icon name="user" class="userIcon"></icon>
      <el-input v-model="form.username" placeholder="请输入用户名" ></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <icon name="lock" class="passwordIcon"></icon>
      <el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
    </el-form-item>
    <el-button type="primary" @click="onSubmit('form')" class="subBtn" :loading="logining">登录</el-button>
    <el-button @click="resetForm('form')">重置</el-button>
  </el-form>
</template>

<script>
  import MenuUtils from "@/utils/MenuUtils";
  var routers = [];
  export default {
    data() {
      return {
        photoValidate: "",
        photoValidateKey: "",
        phoneShow: false,
        logining: false,
        sending: false,
        form: {
          username: "",
          password: "",
        },
        rules: {
          username: [{ required: true, message: "请输入账号", trigger: "blur" }],
          password: [{ required: true, message: "请输入密码", trigger: "blur" }],

        }
      };
    },
    created() {
      this.$store.state.routes.routes = {}
    },
    methods: {
      onSubmit(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.logining = true;
            var obj = {
              data:{
                usercode:this.form.username,
                password:this.form.password
              }
            }
            this.$http('noAuth/sysloginIn.do',obj).then(resp => {
              if(resp.code==1){
                this.getMenu_sidebar();
                window.sessionStorage.setItem('username',this.form.username)
                window.sessionStorage.setItem("isShowPwd", false);
              }else{
                this.$message({
                  message:resp.msg,
                  type:'error'
                })
              }
              this.logining = false;
            });
          } else {
            return false;
          }
        });
      },
      getMenu_sidebar() {
        this.$http('noAuth/user/authUrls.do').then(resp=>{
          if(resp.code==1){
//            列表权限开始----------------------------
            resp.data.indexOf('/sys/financingdayfee/list.do')>-1 ? this.$store.state.routes.routes.ywKouXi = true:this.$store.state.routes.routes.ywKouXi = false;
            resp.data.indexOf('/sys/fee/stockDetailList.do')>-1 ? this.$store.state.routes.routes.ywFeilv = true:this.$store.state.routes.routes.ywFeilv = false

            resp.data.indexOf('/sys/user/listUser.do')>-1 ? this.$store.state.routes.routes.yh = true:this.$store.state.routes.routes.yh = false

            resp.data.indexOf('/sys/financing/list.do')>-1 ? this.$store.state.routes.routes.faAll = true:this.$store.state.routes.routes.faAll = false
            resp.data.indexOf('/sys/financing/list.do')>-1 ? this.$store.state.routes.routes.faSettle = true:this.$store.state.routes.routes.faSettle = false
            resp.data.indexOf('/sys/financing/listExpire.do')>-1 ? this.$store.state.routes.routes.faTimed = true:this.$store.state.routes.routes.faTimed = false

            resp.data.indexOf('/sys/recharge/list.do')>-1 ? this.$store.state.routes.routes.cwRecharge = true:this.$store.state.routes.routes.cwRecharge = false
            resp.data.indexOf('/sys/membercash/list.do')>-1 ? this.$store.state.routes.routes.cwWithDraw = true:this.$store.state.routes.routes.cwWithDraw = false
            resp.data.indexOf('/sys/membercash/list.do')>-1 ? this.$store.state.routes.routes.cwWithdrawRecord = true:this.$store.state.routes.routes.cwWithdrawRecord = false
            resp.data.indexOf('/listFinanceStatistics.do')>-1 ? this.$store.state.routes.routes.cwCount = true:this.$store.state.routes.routes.cwCount = false

            resp.data.indexOf('/sys/user/list.do')>-1 ? this.$store.state.routes.routes.xtAdmin = true:this.$store.state.routes.routes.xtAdmin = false
            resp.data.indexOf('/sys/permisssion/list.do')>-1 ? this.$store.state.routes.routes.xtAccess = true:this.$store.state.routes.routes.xtAccess = false
            resp.data.indexOf('/sys/role/list.do')>-1 ? this.$store.state.routes.routes.xtRole = true:this.$store.state.routes.routes.xtRole = false
            resp.data.indexOf('/sys/log/list.do')>-1 ? this.$store.state.routes.routes.xtLog = true:this.$store.state.routes.routes.xtLog = false

//            列表权限完毕----------------------------
            resp.data.indexOf('/sys/financingdayfee/deduct.do')>-1 ? this.$store.state.routes.routes.ywBqOperate = true:this.$store.state.routes.routes.ywBqOperate = false //补扣
          console.log(resp.data.indexOf('/sys/feetemp/addOrModify.do')>-1)
          resp.data.indexOf('/sys/feetemp/addOrModify.do')>-1 ? this.$store.state.routes.routes.ywFlOperate = true:this.$store.state.routes.routes.ywFlOperate = false //费率编辑提交
            resp.data.indexOf('/sys/recharge/line.do')>-1 ? this.$store.state.routes.routes.yhxxczOperate = true:this.$store.state.routes.routes.yhxxczOperate = false//用户线下充值
            resp.data.indexOf('/sys/user/financeList.do')>-1 ? this.$store.state.routes.routes.yhWater = true:this.$store.state.routes.routes.yhWater = false//用户资金流水
            resp.data.indexOf('/sys/user/userMsgDetail.do')>-1 ? this.$store.state.routes.routes.yhDetail = true:this.$store.state.routes.routes.yhDetail = false//用户详情
            resp.data.indexOf('/sys/bankcard/unbundling.do')>-1 ? this.$store.state.routes.routes.yhjbOperate = true:this.$store.state.routes.routes.yhjbOperate = false //解绑银行卡
            resp.data.indexOf('/sys/recharge/audit.do')>-1 ? this.$store.state.routes.routes.yhczshOperate = true:this.$store.state.routes.routes.yhczshOperate = false //充值审核
            resp.data.indexOf('/sys/membercash/handpay.do')>-1 ? this.$store.state.routes.routes.yhtxsdOperate = true:this.$store.state.routes.routes.yhtxsdOperate = false //提现手动打款
            resp.data.indexOf('/sys/membercash/cancle.do')>-1 ? this.$store.state.routes.routes.yhtxqxOperate = true:this.$store.state.routes.routes.yhtxqxOperate = false  //提现取消

            resp.data.indexOf('/sys/financeAccount/liquidation.do')>-1 ? this.$store.state.routes.routes.sqjsapply = true:this.$store.state.routes.routes.sqjsapply = false  //申请结算
            resp.data.indexOf('/sys/financeAccount/refuseLiquidation.do')>-1 ? this.$store.state.routes.routes.qxjsapply = true:this.$store.state.routes.routes.qxjsapply = false  //取消结算

            resp.data.indexOf('/sys/user/add.do')>-1 ? this.$store.state.routes.routes.xtAdminAdd = true:this.$store.state.routes.routes.xtAdminAdd = false  //管理员管理
            resp.data.indexOf('/sys/user/modifyState.do')>-1 ? this.$store.state.routes.routes.xtAdminState = true:this.$store.state.routes.routes.xtAdminState = false  //
            resp.data.indexOf('/sys/user/resetPassword.do')>-1 ? this.$store.state.routes.routes.xtAdminRePwd = true:this.$store.state.routes.routes.xtAdminRePwd = false  //
            resp.data.indexOf('/sys/user/del.do')>-1 ? this.$store.state.routes.routes.xtAdmindel = true:this.$store.state.routes.routes.xtAdmindel = false  //
            resp.data.indexOf('/sys/user/addRole.do')>-1 ? this.$store.state.routes.routes.xtAdminToRole = true:this.$store.state.routes.routes.xtAdminToRole = false  //

            resp.data.indexOf('/sys/role/del.do')>-1 ? this.$store.state.routes.routes.xtRoleDel = true:this.$store.state.routes.routes.xtRoleDel = false  //角色管理
            resp.data.indexOf('/sys/role/add.do')>-1 ? this.$store.state.routes.routes.xtRoleAdd = true:this.$store.state.routes.routes.xtRoleAdd = false  //
            resp.data.indexOf('/sys/role/modify.do')>-1 ? this.$store.state.routes.routes.xtRoleEdit = true:this.$store.state.routes.routes.xtRoleEdit = false  //
            resp.data.indexOf('/sys/role/addPermission.do')>-1 ? this.$store.state.routes.routes.xtRoleToAccess = true:this.$store.state.routes.routes.xtRoleToAccess = false  //

            resp.data.indexOf('/sys/permisssion/del.do')>-1 ? this.$store.state.routes.routes.xtAccessDel = true:this.$store.state.routes.routes.xtAccessDel = false  //权限管理
            resp.data.indexOf('/sys/permisssion/add.do')>-1 ? this.$store.state.routes.routes.xtAccessAdd = true:this.$store.state.routes.routes.xtAccessAdd = false  //
            resp.data.indexOf('/sys/permisssion/modify.do')>-1 ? this.$store.state.routes.routes.xtAccessEdit = true:this.$store.state.routes.routes.xtAccessEdit = false  //

            this.$router.push({ path: "/welcome" });
          }
          window.sessionStorage.setItem('routeConst',JSON.stringify(this.$store.state.routes.routes))
        })
//        var xx = [
//          {
//            name: "业务管理",
//            path: "/",
//            component: "systemPub",
//            iconCls: "el-icon-star-on",
//            hidden: false,
//            leaf: false,
//            children: [
//              {
//                name: "扣息记录",
//                path: "yewu_Charges",
//                component: "yewu_Charges",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true,
//              },
//              {
//                name: "费率记录",
//                path: "yewu_feeConfig",
//                component: "yewu_feeConfig",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true
//              }
//            ]
//          },
//          {
//            name: "",
//            path: "/",
//            component: "systemPub",
//            iconCls: "el-icon-star-on",
//            hidden: false,
//            leaf: true,
//            children: [
//              {
//                name: "用户",
//                path: "userConfig",
//                component: "userConfig",
//                iconCls: "el-icon-star-on",
//                leaf: true,
//              },
//            ]
//          },
//          {
//            name: "方案管理",
//            path: "/",
//            component: "systemPub",
//            iconCls: "el-icon-star-on",
//            hidden: false,
//            leaf: false,
//            children: [
//              {
//                name: "所有方案",
//                path: "fa_list",
//                component: "fa_list",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true,
//              },
//              {
//                name: "即将到期方案",
//                path: "fa_timer",
//                component: "fa_timer",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true,
//              },
//
//            ]
//          },
//          {
//            name: "财务管理",
//            path: "/",
//            component: "systemPub",
//            iconCls: "el-icon-star-on",
//            hidden: false,
//            leaf: false,
//            children: [
//              {
//                name: "充值记录",
//                path: "cw_recharge",
//                component: "cw_recharge",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true,
//              },
//              {
//                name: "提现申请",
//                path: "cw_withdraw",
//                component: "cw_withdraw",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true
//              },
//              {
//                name: "提现记录",
//                path: "cw_withdrawRecord",
//                component: "cw_withdrawRecord",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true
//              },
//              {
//                name: "财务统计",
//                path: "cw_count",
//                component: "cw_count",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true
//              }
//            ]
//          },
//          {
//            name: "系统管理",
//            path: "/",
//            component: "systemPub",
//            iconCls: "el-icon-star-on",
//            hidden: false,
//            leaf: false,
//            children: [
//              {
//                name: "管理员账号",
//                path: "xitong_admin",
//                component: "xitong_admin",
//                iconCls: "el-icon-star-on",
//                hidden: false,
//                leaf: true,
//              },
//              {
//                name: "权限管理",
//                path: "xitong_access",
//                component: "xitong_access",
//                iconCls: "el-xitong_access-star-on",
//                hidden: false,
//                leaf: true
//              },
//              {
//                name: "角色管理",
//                path: "xitong_role",
//                component: "xitong_role",
//                iconCls: "el-xitong_access-star-on",
//                hidden: false,
//                leaf: true
//              }, {
//                name: "管理员配角色",
//                path: "xitong_adminRoleDetail",
//                component: "xitong_adminRoleDetail",
//                iconCls: "el-xitong_access-star-on",
//                hidden: true,
//                leaf: true
//              },
//              {
//                name: "角色配权限",
//                path: "xitong_roleAccessDetail",
//                component: "xitong_roleAccessDetail",
//                iconCls: "el-xitong_access-star-on",
//                hidden: true,
//                leaf: true
//              },
//              {
//                name: "日志管理",
//                path: "xitong_log",
//                component: "xitong_log",
//                iconCls: "el-xitong_access-star-on",
//                hidden: false,
//                leaf: true
//              },
//            ]
//          },
//        ];
//        console.log(JSON.stringify(arr))
//        this.login(xx)
//        this.$router.addRoutes(routers);


      },
      login(data) {
        window.sessionStorage.setItem("user", JSON.stringify(data));
        MenuUtils(routers, data);
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  };
</script>

<style scoped>
  .login-container {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  .login-container {
    margin-bottom: 0;
  }
  .title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }

  .el-form-item {
    margin-bottom: 22px;
    margin-right: 15px;
  }

  .subBtn {
    margin-left: 30px;
    margin-top: 20px;
  }

  .userIcon,
  .passwordIcon,
  .file-picture-o,
  .mobile {
    transform: scale(1.6);
    position: absolute;
    left: -40px;
    top: 11px;
  }
  .file-picture-o {
    transform: scale(1.4);
  }
  .passwordIcon {
    top: 10px;
  }
  .mobile {
    transform: scale(2.2);
  }
  .photoValidate {
    width: 80px;
    line-height: 35px;
    height: 35px;
    background: #409eff;
    border-color: #409eff;
    color: white;
    font-size: 20px;
    letter-spacing: 5px;
    font-weight: bold;
    border-radius: 5%;
  }
  .el-icon-refresh:hover {
    cursor: pointer;
  }
</style>
